package com.supermarket.api.web;

import com.supermarket.api.bean.IndexContentRes;
import com.supermarket.api.common.BaseResponse;
import com.supermarket.api.common.PageParam;
import com.supermarket.api.entity.ProductEntity;
import com.supermarket.api.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 首页接口
 * @author li
 */
@Controller
@RequestMapping("/index")
public class IndexController {

    /**
     * 轮播广告
     */
    @Autowired
    private AdvertiseService advertiseService;
    /**
     * 精选分类
     */
    @Autowired
    private SelectedCategoryService selectedCategoryService;
    /**
     * 推荐品牌
     */
    @Autowired
    private ShopService shopService;
    /**
     * 商品
     */
    @Autowired
    private ProductService productService;
    /**
     * 人气推荐商品
     */
    @Autowired
    private HotProductService hotProductService;
    /**
     * 新鲜好物商品
     */
    @Autowired
    private NewProductService newProductService;

    @ResponseBody
    @GetMapping("/content")
    public String content(){
        IndexContentRes indexContentRes = new IndexContentRes();
        indexContentRes.setAdvertiseList(advertiseService.list());
        indexContentRes.setCategoryList(selectedCategoryService.list());
        indexContentRes.setShopList(shopService.topList(6));
        indexContentRes.setHotProductList(hotProductService.topList(6));
        indexContentRes.setNewProductList(newProductService.topList(6));
        return BaseResponse.successJson(indexContentRes);
    }

    @ResponseBody
    @GetMapping("/new")
    public String newProduct(PageParam pageParam){
        Page<ProductEntity> page = newProductService.list(pageParam);
        return BaseResponse.successJson(page);
    }

    @ResponseBody
    @GetMapping("/hot")
    public String hotProduct(PageParam pageParam){
        Page<ProductEntity> page = hotProductService.list(pageParam);
        return BaseResponse.successJson(page);
    }

    @ResponseBody
    @GetMapping("/guess")
    public String guess(PageParam pageParam){
        Page<ProductEntity> page = productService.list(pageParam);
        return BaseResponse.successJson(page);
    }

}
